<script type="text/javascript" src="<?=site_url()?>js/punvalidate.js"></script>
<script language="javascript">
	function handleNetwork(obj) {
	var txt = 'txtNetMobile' + obj.id.substring(obj.id.length - 2);
		if(obj.value == "อื่นๆ (โปรดระบุ)") {
			document.getElementById(txt).style.visibility="visible";
			document.getElementById(txt).focus();
		} else {
			document.getElementById(txt).style.visibility="hidden";
			document.getElementById(txt).value = '';
		}
	}
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function checkImageExt(obj) {
		var t = obj.value;
		var txt = obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();
		if(!(txt == "jpg" || txt == "jpeg" || txt == "gif" || txt == "png" || txt == "pdf")) {
			alert("ไฟล์รูปภาพที่แนบมาไม่ถูกต้อง " + t + "\nกรุณาเลือกไฟล์ใหม่");	
			u = document.getElementById('uploader');
			u.innerHTML=' <input name="txtStudentImg" id="txtStudentImg" type="file" style="width:500px;" onchange="checkImageExt(this);" /> ';
		}
	}
	function validateForm() {
		if(trim(document.getElementById('txtEmail').value).length > 0 && isValidEmailAddress(document.getElementById('txtEmail').value) == false) {
			document.getElementById('txtEmail').focus();
			alert('รูปแบบอีเมล์ไม่ถูกต้อง');
			return false;
		}
		if(trim(document.getElementById('txtTel').value).length > 0 && isTelNo(document.getElementById('txtTel').value) == false) {
			document.getElementById('txtTel').focus();
			alert("รูปแบบเบอร์โทรศัพท์ไม่ถูกต้อง");
			return false;		
		}
		if(trim(document.getElementById('txtMobile01').value).length > 0 && isTelNo(document.getElementById('txtMobile01').value) == false) {
			document.getElementById('txtMobile01').focus();
			alert("รูปแบบเบอร์โทรศัพท์ไม่ถูกต้อง");
			return false;		
		}
		if(trim(document.getElementById('txtMobile02').value).length > 0 && isTelNo(document.getElementById('txtMobile02').value) == false) {
			document.getElementById('txtMobile02').focus();
			alert("รูปแบบเบอร์โทรศัพท์ไม่ถูกต้อง");
			return false;		
		} 
		return true;
	}
</script>
<div id="mainContent">
<?=form_open_multipart('StudentInfo/saveContractInfo', array('onsubmit' => 'return validateForm();'));?>
<input type="hidden" name="studentId" id="studentId" value="<?php if(isset($student_id)) echo $student_id;?>" />
<table width="1000px" border="0" cellspacing="2px" cellpadding="0" align="center" >
	<tr align="center">
    	<td>
    		<?php
    			if(isset($student_id)) {
    				echo ' <h2><b><font color="blue">'. $first_name .' ' . $last_name .'</font></h2> ';
					echo ' [<a href="'.site_url().'StudentInfo/detail/'.$student_id.'" >ประวัติส่วนตัว</a>] | 
						   [<a href="'.site_url().'StudentInfo/detailContractInfo/'.$student_id.'" >ข้อมูลการติดต่อ</a>]| 
						   [<a href="'.site_url().'StudentInfo/detailBooking/'.$student_id.'" >ข้อมูลการจอง</a>]   | 
						   [<a href="'.site_url().'StudentInfo/detailStudied/'.$student_id.'" >ประวัติกับสถาบัน</a>] ';     				
    			} else {
    				echo " [ประวัติส่วนตัว] | [ข้อมูลการติดต่อ]| [ข้อมูลการจอง] | [ประวัติกับสถาบัน] ";
    			}
    		?>	
    	</td>
    </tr>
	<tr style="height:10px;">
    	<td></td>
    </tr>
	 <tr>
    	<td align="center">
        <fieldset style="width: 950px;">
          <legend>ข้อมูลการติดต่อ</legend>
          	<?php if($form_status != 'notPermit') {?>
                <table width="950px" border="0" cellspacing="2px" cellpadding="0">
                  <col width="150px" />
                  <col width="*" />
                  <col width="150px" />
                  <tr>
                    <td align="right"><label>E-mail</label></td>
                    <td align="left"><input name="txtEmail" type="text" id="txtEmail" maxlength="45" value="<?php if(isset($email)) echo $email; ?>" />
                     โทรศัพท์บ้าน <input name="txtTel" type="text" id="txtTel" maxlength="20" value="<?php if(isset($telephone_home)) echo $telephone_home; ?>" /></td>
                    <td rowspan="8"><a href="<?=site_url()?>data-image/student/<?php if(isset($add_image) == false) echo 'noImg.jpg'; else echo $add_image; ?>" target="_blank" ><img src="<?=site_url()?>data-image/student/<?php if(isset($add_image) == false) echo 'noImg.jpg'; else echo $add_image; ?>" width="150px" /></a></td>
                  </tr>
                  <tr>
                    <td align="right" style="vertical-align:top;"><label>โทรศัพท์มือถือ</label></td>
                    <td align="left">1. <input name="txtMobile01" type="text" id="txtMobile01" maxlength="20" value="<?php if(isset($mobile01)) echo $mobile01; ?>" />
                       
                      เครือข่าย
                      <select name="selNetMobile01" id="selNetMobile01" onchange="handleNetwork(this);">
                        <option value="AIS" <?php if(isset($mobile01_network) == false || $mobile01_network == 'AIS') echo 'selected="selected"';?>>AIS</option>
                        <option value="DTAC" <?php if(isset($mobile01_network)  && $mobile01_network == 'DTAC') echo 'selected="selected"';?>>DTAC</option>
                        <option value="True Move" <?php if(isset($mobile01_network)  && $mobile01_network == 'True Move') echo 'selected="selected"';?>>True Move</option>
                        <option value="Hutch" <?php if(isset($mobile01_network)  && $mobile01_network == 'Hutch') echo 'selected="selected"';?>>Hutch</option>
                        <option value="ไม่ทราบ" <?php if(isset($mobile01_network)  && $mobile01_network == 'ไม่ทราบ') echo 'selected="selected"';?>>ไม่ทราบ</option>
                        <option value="อื่นๆ (โปรดระบุ)" <?php if(isset($mobile01_network) && $mobile01_network != 'AIS' && $mobile01_network != 'DTAC' && $mobile01_network != 'True Move'  && $mobile01_network != 'Hutch' && $mobile01_network != 'ไม่ทราบ') echo 'selected="selected"';?>>อื่นๆ (โปรดระบุ)</option>
                      </select>
                      <input name="txtNetMobile01" type="text" id="txtNetMobile01" <?php if(!(isset($mobile01_network) && $mobile01_network != 'AIS' && $mobile01_network != 'DTAC' && $mobile01_network != 'True Move'  && $mobile01_network != 'Hutch' && $mobile01_network != 'ไม่ทราบ')) echo ' style="visibility:hidden;" ';?> maxlength="10" value="<?php if(isset($mobile01_network)) echo $mobile01_network; ?>" />
                      <br />
                      2.
                      <input name="txtMobile02" type="text" id="txtMobile02" value="<?php if(isset($mobile02)) echo $mobile02; ?>" />
                      เครือข่าย
                      <select name="selNetMobile02" id="selNetMobile02"  onchange="handleNetwork(this);">
                        <option value="AIS" <?php if(isset($mobile02_network) == false || $mobile02_network == 'AIS') echo 'selected="selected"';?>>AIS</option>
                        <option value="DTAC" <?php if(isset($mobile02_network)  && $mobile02_network == 'DTAC') echo 'selected="selected"';?>>DTAC</option>
                        <option value="True Move" <?php if(isset($mobile02_network)  && $mobile02_network == 'True Move') echo 'selected="selected"';?>>True Move</option>
                        <option value="Hutch" <?php if(isset($mobile02_network)  && $mobile02_network == 'Hutch') echo 'selected="selected"';?>>Hutch</option>
                        <option value="ไม่ทราบ" <?php if(isset($mobile02_network)  && $mobile02_network == 'ไม่ทราบ') echo 'selected="selected"';?>>ไม่ทราบ</option>
                        <option value="อื่นๆ (โปรดระบุ)" <?php if(isset($mobile02_network) && $mobile02_network != 'AIS' && $mobile02_network != 'DTAC' && $mobile02_network != 'True Move'  && $mobile02_network != 'Hutch' && $mobile02_network != 'ไม่ทราบ') echo 'selected="selected"';?>>อื่นๆ (โปรดระบุ)</option>
                      </select>
                      <input name="txtNetMobile02" type="text" id="txtNetMobile02" <?php if(!(isset($mobile02_network) && $mobile02_network != 'AIS' && $mobile02_network != 'DTAC' && $mobile02_network != 'True Move'  && $mobile02_network != 'Hutch' && $mobile02_network != 'ไม่ทราบ')) echo 'style="visibility:hidden;"';?>  maxlength="10" value="<?php if(isset($mobile02_network)) echo $mobile02_network; ?>" />
                      <br />                      </td>
                  </tr>
                  <tr>
                    <td align="right" style="vertical-align:top"><label>ที่อยู่</label></td>
                    <td align="left">เลขที่่ห้องพัก
                          <input name="txtRoomNo" type="text" id="txtRoomNo" size="5" maxlength="10" value="<?php if(isset($add_room_no)) echo $add_room_no; ?>" />
บ้านเลขที่
<input name="txtHomeNo" type="text" id="txtHomeNo" size="5" maxlength="10" value="<?php if(isset($add_home_no)) echo $add_home_no; ?>" />
ชื่ออาคาร/คอนโดมิเนียม
<input name="txtBuilding" type="text" id="txtBuilding" maxlength="45" value="<?php if(isset($add_building_name)) echo $add_building_name; ?>" />
<br />
หมู่ที่
<input name="txtMoo" type="text" id="txtMoo" size="5" maxlength="10" value="<?php if(isset($add_moo)) echo $add_moo; ?>" />
ซอย
<input name="txtSoi" type="text" id="txtSoi" maxlength="45" value="<?php if(isset($add_soi)) echo $add_soi; ?>" />
ถนน
<input name="txtRoad" type="text" id="txtRoad" maxlength="45" value="<?php if(isset($add_road)) echo $add_road; ?>" />
<br />
แขวง
<input name="txtDistinct" type="text" id="txtDistinct" maxlength="45" value="<?php if(isset($add_district)) echo $add_district; ?>" />
เขต
<input name="txtArea" type="text" id="txtArea" maxlength="45" value="<?php if(isset($add_area)) echo $add_area; ?>" />
จังหวัด
<input name="txtProvince" type="text" id="txtProvince" maxlength="45" value="<?php if(isset($add_province)) echo $add_province; ?>" />
<br />
รหัสไปรษณีย์
<input name="txtPostCode" type="text" id="txtPostCode" size="15" maxlength="6" value="<?php if(isset($add_post_code)) echo $add_post_code; ?>" />
<br />
ข้อมูลอื่นๆ เช่น จุดสังเกตใกล้เคียง
<input name="txtAddNote" type="text" id="txtAddNote" size="65" maxlength="100" value="<?php if(isset($add_note)) echo $add_note; ?>" />
                                      </td>
                  </tr>
                  <tr>
                    <td align="right" ><label>รูปแผนที่</label></td>
                    <td align="left"><input name="txtMap" id="txtMap" type="file" onchange="checkImageExt(this);" /></td>
                  </tr>
                  
                  <tr>
                    <td align="right" ><label>ชื่อผู้กรอกข้อมูล</label></td>
                    <td align="left">(<span class="style1">กรณีที่นักเรียนไม่ได้กรอกด้วยตนเอง</span>)</td>
                  </tr>
                  <tr>
                    <td align="right" ><label>ชื่อ</label></td>
                    <td align="left"><input name="txtWFName" type="text" id="txtWFName" value="<?php if(isset($first_name_writer)) echo $first_name_writer; ?>" />
                      <label> นามสกุล </label>
                      <input name="txtWLName" type="text" id="txtWLName" value="<?php if(isset($last_name_writer)) echo $last_name_writer; ?>" /></td>
                  </tr>
                  <tr>
                    <td align="right" ><label>โทรศัพท์มือถือ</label></td>
                    <td align="left"><input name="txtWMobile" type="text" id="txtWMobile" value="<?php if(isset($telephone_writer)) echo $telephone_writer; ?>" />
                      เครือข่าย
                        <select name="selNetMobile03" id="selNetMobile03"  onchange="handleNetwork(this);">
	                          <option value="AIS" <?php if(isset($telephone_network) == false || $telephone_network == 'AIS') echo 'selected="selected"';?>>AIS</option>
	                        <option value="DTAC" <?php if(isset($telephone_network)  && $telephone_network == 'DTAC') echo 'selected="selected"';?>>DTAC</option>
	                        <option value="True Move" <?php if(isset($telephone_network)  && $telephone_network == 'True Move') echo 'selected="selected"';?>>True Move</option>
	                        <option value="Hutch" <?php if(isset($telephone_network)  && $telephone_network == 'Hutch') echo 'selected="selected"';?>>Hutch</option>
	                        <option value="ไม่ทราบ" <?php if(isset($telephone_network)  && $telephone_network == 'ไม่ทราบ') echo 'selected="selected"';?>>ไม่ทราบ</option>
	                        <option value="อื่นๆ (โปรดระบุ)" <?php if(isset($telephone_network) && $telephone_network != 'AIS' && $telephone_network != 'DTAC' && $telephone_network != 'True Move'  && $telephone_network != 'Hutch' && $telephone_network != 'ไม่ทราบ') echo 'selected="selected"';?>>อื่นๆ (โปรดระบุ)</option>
                        </select>
                    <input name="txtNetMobile03" type="text" id="txtNetMobile03" <?php if(!(isset($telephone_network) && $telephone_network != 'AIS' && $telephone_network != 'DTAC' && $telephone_network != 'True Move'  && $telephone_network != 'Hutch' && $telephone_network != 'ไม่ทราบ')) echo 'style="visibility:hidden;"';?>  maxlength="10" value="<?php if(isset($telephone_network)) echo $telephone_network; ?>" /></td>
                  </tr>
                  <tr style="height: 10px;">
                    <td align="right" ></td>
                    <td align="left"></td>
                  </tr>
        </table>
        <?php } else { echo '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>';} ?>
          </fieldset>
        </td>
    </tr>
   
    <tr style="height:10px;">
    	<td></td>
    </tr>
    <tr >
    <?php if($form_status != 'notPermit') {?>
        <td align="center"><input name="" type="submit"  value="บันทึกข้อมูล"/>
     <?php } ?>
          <br /></td>
    </tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
</table>
<?=form_close();?> 
</div>